package com.xcode.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
public class TestMvc {

	@RequestMapping("/test.do")
	public String test(){
		System.out.println("test sucess");
//		return "sucess";
		return "error";
	}
	
	@RequestMapping("/login.do")
	public String login(){
		System.out.println("login sucess");
		
		return "/WEB-INF/Views/sucess";
	}
	
	@RequestMapping("/testajax.do")
	public String testajax(HttpServletResponse response){
		System.out.println("test ajax");
		List<String> lists=new ArrayList<String>();
		lists.add("sadsa");
		lists.add("admin");
		lists.add("test");
		try {
			PrintWriter writer=response.getWriter();
			writer.print(lists);
//			writer.print("sadsa");
			writer.flush();
			writer.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return "ajax sucess";
	}
	
	@RequestMapping(value="/testrest{id}",method=RequestMethod.DELETE)
	public String testRestDelete(@PathVariable Integer id){
		
		System.out.println(id.toString());
		return "error";
	}
	
	@RequestMapping(value="/testrest",method=RequestMethod.POST)
	public String testRestPost(){
		System.out.println("restpost");
		
		return "error";
	}
	
}
